package com.yh.controller.api;

import com.yh.anno.IdempotencyHandler;
import com.yh.service.PayService;
import com.yh.vo.ResponseVO;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author yuhuan
 * @date 2022/01/13
 */
@RestController
@RequestMapping("/api/pay")
public class PayWeb {
    @DubboReference(check = false)
    private PayService payService;

    /**
     * 虚拟支付，仅用作测试
     * 服务地址 http://localhost:8080/api/pay/virtual
     */
    @RequestMapping("virtual")
    @IdempotencyHandler
    public ResponseVO virtualPayment(String orderId) {
        int payState = payService.virtualPaymentOfCode(orderId);
        return ResponseVO.buildSuccessInstance(payState);
    }

    /**
     * 虚拟退款，仅用作测试
     * 服务地址 http://localhost:8080/api/pay/virtual/refund
     */
    @RequestMapping("/virtual/refund")
    public ResponseVO virtualRefund(String orderId, String dateTimeStr) {
        int payState = payService.virtualRefund(orderId, dateTimeStr);
        return ResponseVO.buildSuccessInstance(payState);
    }
}
